import CryptoJS from 'crypto-js';
const AES_PUBLIC_KEY = "Md#CBCrFh@HCEtxg";
const AES_ENCRYPT_SALT = "@$#=%^&*A8#&25^%";
const DEFAULT_OPTIONS = {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
    iv: ''
};
class Encrypt {
    getKey(timeStamp) {
        let str = CryptoJS.MD5(AES_PUBLIC_KEY + timeStamp + AES_ENCRYPT_SALT).toString();
        let chars = [];
        for (let i = 0; i < 16; i++) {
            chars[i] = str.charAt(parseInt((i * 2 + (timeStamp / 1000) % 2)));
        }
        let dataKey = chars.join("");
        let output = CryptoJS.enc.Utf8.parse(dataKey).toString(CryptoJS.enc.Hex);
        return CryptoJS.enc.Hex.parse(output);
    }
    encode(word, timeStamp) {
        return CryptoJS.AES.encrypt(word, this.getKey(timeStamp), DEFAULT_OPTIONS).toString();
    }
    decode(word, timeStamp) {
        return CryptoJS.AES.decrypt(word, this.getKey(timeStamp), DEFAULT_OPTIONS).toString(CryptoJS.enc.Utf8)
    }
}
export default Encrypt;